﻿package extremefx.geom {
	import extremefx.ICloneable;
	import extremefx.IEquatable;
	/**
	 * @author Marcelo Volmaro
	 */
	public class Size implements ICloneable, IEquatable {
		public var width:uint;
		public var height:uint;
		
		/**
		 * @param pArgs [Size]|[Point]|[x:int, y:int]
		 */
		public function Size(... pArgs) {
			var arg0:* = pArgs[0];
			
			if (pArgs.length == 1){
				if (arg0 is Size){
					setSize(arg0.width, arg0.height);
					
				} else if (arg0 is XPoint){
					setSize(arg0.x, arg0.y);
				}
				
			} else {
				setSize(arg0, pArgs[1]);
			}
		}
		
		public function clone():Object {
			return new Size(this);
		}
		
		public function isEmpty():Boolean {
			return !(width || height);
		}
		
		public function setSize(pWidth:int, pHeight:int):void{
			width = pWidth;
			height = pHeight;
		}
		
		public function toPoint():XPoint {
			return new XPoint(width, height);
		}
		
		public function times(pFactor:Number):Size {
			return new Size(width * pFactor, height * pFactor);
		}
		
		public function divide(pFactor:Number):Size {
			return new Size(width / pFactor, height / pFactor);
		}
		
		public function plus(pSize:Size):Size {
			return new Size(width + pSize.width, height + pSize.height);
		}
		
		public function minus(pSize:Size):Size {
			return new Size(width - pSize.width, height - pSize.height);
		}
		
		public function equals(pObj:*):Boolean {
			if (pObj is Size){
				var o:Size = Size(pObj);
				return o.width == width && o.height == height;
			}
			return false;
		}
		
		public function toString():String {
			return "(w:"+width+", h:"+height+")";
		}
	}
}
